package nowCoder;

import java.util.Scanner;

/**
 * @Auther: zzx
 * @Date: 2024.02.24/2/3
 */
public class HJ39 {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String x = in.nextLine();
        String y = in.nextLine();
        String z = in.nextLine();
        String[] xx = x.split("\\.");
        StringBuilder sb = new StringBuilder();
        if(xx.length != 4){
            System.out.print("1");
            return;
        }
        for (String s : xx) {
            try {
                int n = Integer.parseInt(s);
                if(n<0 ||n > 255){
                    System.out.print("1");
                    return;
                }
                for (int j = 7; j >= 0; j--) {
                    sb.append((n & (1 << j)) > 0 ? "1" : "0");
                }
            } catch (Exception e) {
                System.out.print("1");
                return;
            }
        }
        int a = sb.length();
        for(int i = 0; i<sb.length();i++){
            if(sb.charAt(i) == '0'){
                a = i;
            }else if(a < i){
                System.out.print("1");
                return;
            }
        }
        String[] yy = y.split("\\.");
        String[] zz = z.split("\\.");
        if (yy.length != 4 || zz.length != 4){
            System.out.print("1");
            return;
        }
        a = 0;
        for (int i = 0 ; i< 4; i++){
            int n = Integer.parseInt(sb.substring(i * 8, (i + 1) * 8), 2);
            int o = Integer.parseInt(yy[i]);
            int p = Integer.parseInt(zz[i]);
            if(o < 0 || o>255 || p < 0 || p>255){
                System.out.print("1");
                return;
            }
            if ((Integer.parseInt(yy[i]) & n) != ((Integer.parseInt(zz[i]) & n))){
                a = 2;
            }
        }
        System.out.print(a);
    }
}
